package com.gzhryc.shared_device.oem.micro.queue.handlers;

import com.gzhryc.common.event.AbsDelayHandler;
import com.gzhryc.common.logging.Logger;
import com.gzhryc.shared_device.base.enums.EPayState;
import com.gzhryc.shared_device.oem.code.member.dao.db.MemberRechargeOrder;
import com.gzhryc.shared_device.oem.code.member.event.MemberRechargeFinishEvent;
import com.gzhryc.shared_device.oem.code.member.services.MemberRechargeOrderService;
import com.gzhryc.shared_device.oem.code.statistics.services.ProjectDayStatisticsService;

import java.util.Date;

public class MemberRechargeFinishEventHandler extends AbsDelayHandler<MemberRechargeFinishEvent> {

    static Logger log = Logger.getLogger(UserAutoTransferMoneyEventHandler.class);

    @Override
    public boolean execute(MemberRechargeFinishEvent event) {
        Date createDate = event.getCreateDate();
        if(createDate == null){
            createDate = new Date();
        }
        MemberRechargeOrder memberRechargeOrder = MemberRechargeOrderService.self(createDate).getByTradeNo(event.getTradeNo());
        if(memberRechargeOrder != null){
            if(EPayState.Success.index().equals(memberRechargeOrder.getPayState())){
                ProjectDayStatisticsService.self().addOneRechargeData(memberRechargeOrder.getCreateDate(),memberRechargeOrder.getMoney());
            }
        }else{
            log.error("未找到订单号为{{0}}的充值订单",event.getTradeNo());
        }
        return true;
    }
}
